package com.cmap;

import java.util.ArrayList;
import java.util.ConcurrentModificationException;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

public class CMapTest {
    static final int HASH_BITS = 0x7fffffff; // usable bits of normal node hash

    public static void main(String[] args) {
        ConcurrentHashMap<Integer, Integer> m = new ConcurrentHashMap<Integer, Integer>();
        for (int i = 0; i < 16; i++) {

            if (i == 0) {
                m.put(i, i);//正常新增（演示）
            } else if (i == 11) {

                m.put(i, i);//扩容（演示）

            } else if (i == 10) {
                m.put(27, 27);
                m.put(43, 43);
            } else if (i == 9) {


            } else {
                m.put(i, i);//正常新增
            }
        }

        m.get(8);
        System.out.println(m);
    }

    //哈希冲突
    static void testHashCode() {
        System.out.println((16 - 1) & spread(new Integer(27).hashCode()));
        System.out.println((16 - 1) & spread(new Integer(43).hashCode()));
        System.out.println((16 - 1) & spread(new Integer(11).hashCode()));
    }

    static final int spread(int h) {
        return (h ^ (h >>> 16)) & HASH_BITS;
    }
}
